const {mongoose}=require("../utils/db");

const userSchema = mongoose.Schema({
    username:{type:String,required:true},
    password:{type:String,required:true},
    userId:{type:String,require:true},
    email:{type:String},
    nikename:{type:String},
    mobile:{type:String}
})


const userModel = mongoose.model("users",userSchema);


//添加
const register =(info)=>{
    const userEty = new userModel(info);
   return userEty.save()
    .then(res=>res)
    .catch(err=>{
        console.log(err)
    })
}

//查询
const login =(query)=>{
    
     return userModel.find(query)
     .then(res=>res)
     .catch(err=>{
         console.log(err)
     })
}

//更新
const update =(info)=>{
    const {query,updated} = info
    return userModel.updateOne(query,updated)
    .then(res=>res)
    .catch(err=>{
        console.log(err)
    })
}

module.exports={
    register,
    login,
    update
}
